﻿using LiteBlog.Components.Contracts;
using LiteBlog.Controllers.Contracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LiteBlog.Controllers.Tests
{
    [TestClass]
    public class ScheduleControllerTests : ControllerTests<IScheduleController>
    {
        [TestMethod]
        public void PublishCallsPublishScheduled()
        {
            _controller.Publish();
            var mock = Mock.Get<IBlogComp>(_controller.BlogComponent);
            mock.Verify(b => b.PublishScheduled());
        }

        [TestMethod]
        public void BackupGetsSettings()
        {
            _controller.Backup();
            var mock = Mock.Get<ISettingsComp>(_controller.SettingsComponent);
            mock.Verify(se => se.Load());
        }

        [TestMethod]
        public void BackupIsValid()
        {
            _settings.ShouldBackup = true;
            _controller.Backup();
            var mock = Mock.Get<IBackupComp>(_controller.BackupComponent);
            mock.Verify(ba => ba.Backup());
        }

        [TestMethod]
        public void BackupIsNotDoneIfNotSet()
        {
            _settings.ShouldBackup = false;
            _controller.Backup();
            var mock = Mock.Get<IBackupComp>(_controller.BackupComponent);
            mock.Verify(ba => ba.Backup(), Times.Never);
        }
    }
}
